package top.wardyan.base.config;

import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * 程序设定. 读取自AppConfig.txt
 * @author ward
 *
 * 2019年2月16日
 */
public class AppConfig {
	
	private static final String FILENAME = "AppConfig.txt";
	protected static final Logger log = Logger.getLogger(AppConfig.class);
	protected static AppConfig instance = null;
	protected Properties prop = null;
	
	protected AppConfig(){
		prop = new Properties();
		try {
			prop.load(new FileReader(FILENAME));
		} catch (IOException e) {
			log.error(e);
		}
	}
	
	public static AppConfig getInstance(){	// synchronized
		if(instance == null) 
			instance = new AppConfig();
		
		return instance;
	}
	
	
	public String get(String key) {
		return prop.getProperty(key);
	}
	
	
	public static void main(String[] args) {
		/**
		AppConfig c = new AppConfig();
		c.configs.forEach((k, v) ->{
			System.out.println("V:" + get(k));
		});
		**/
		//AppConfig c = new AppConfig();
		//System.out.println(AppConfig.get("dbName"));
	}
	
}
